import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

/**
 * Created by WEN on 2016/10/9.
 */
public class IntersectionOfTwoArrays {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> results = new HashSet<Integer>();
        HashSet<Integer> set = new HashSet<Integer>();
        for (int i=0;i<nums1.length;i++){
            set.add(nums1[i]);
        }
        for (int i=0;i<nums2.length;i++){
            if(set.contains(nums2[i]))
                results.add(nums2[i]);
        }
        int[] rel = new int[results.size()];
        int i=0;
        Iterator<Integer> it = results.iterator();
        while (it.hasNext()){
            rel[i]=it.next();
            i++;
        }
        return rel;

    }
}
